package ${packageRootName}.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import ${packageRootName}.entity.${modelBig};
import ${packageRootName}.entity.${modelBig}Example;
import ${packageRootName}.mapper.${modelBig}Mapper;
import ${packageRootName}.pojo.vo.PageBean;
import ${packageRootName}.service.I${modelBig}Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ${modelBig}ServiceImpl implements I${modelBig}Service {
    @Autowired(required = false)
    private ${modelBig}Mapper ${modelSmall}Mapper;

    @Override
    public int insert(${modelBig} ${modelSmall}) {
        return ${modelSmall}Mapper.insertSelective(${modelSmall});
    }

    @Override
    public int delete(Integer ${modelSmall}Id) {
        if (${modelSmall}Id == null){
            return 0;
        }
        return ${modelSmall}Mapper.deleteByPrimaryKey(${modelSmall}Id);
    }

    @Override
    public int update(${modelBig} ${modelSmall}) {
        return ${modelSmall}Mapper.updateByPrimaryKeySelective(${modelSmall});
    }

    @Override
    public PageBean<${modelBig}> page(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        ${modelBig}Example example = new ${modelBig}Example();
        List<${modelBig}> list = ${modelSmall}Mapper.selectByExample(example);
        PageInfo<${modelBig}> info = new PageInfo<>(list);
        return new PageBean<>(info);
    }


    @Override
    public ${modelBig} getById(Integer ${modelSmall}Id){
        if (${modelSmall}Id == null){
            return null;
        }
        ${modelBig}Example example = new ${modelBig}Example();
        example.createCriteria().andIdEqualTo(${modelSmall}Id);
        List<${modelBig}> list = ${modelSmall}Mapper.selectByExample(example);
        if (list!=null && list.size()>0){
            return list.get(0);
        }
        return null;
    }
}
